﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenTKLightingTool.Helper;
using Ignitron.EEngine;
using Ignitron.EEngine.Maths;
using Ignitron.EEngine.Lighting;

namespace OpenTKLightingTool.Data
{
    internal class LightRecord
    {
        public int Index
        { get; set; }

        public bool IsVisible
        {
            get
            {
                return mData[Index].IsEnabled;
            }
        }

        public string Title
        {
            get
            {
                return "Light" + Index.ToString();
            }
        }

        public LightDictionary mData
        { get; set;}
    }

    /// <summary>
    /// Dictionary of lights
    /// </summary>
    internal class LightDictionary : List<Light>
    {
        private const int maxLights = 8;


        /// <summary>
        /// Constructor
        /// </summary>
        public LightDictionary(IEngine engine)
        {            
            for (int i = 0; i < maxLights; i++)
            {
                Add(new Light(engine));
            }
        }

        /// <summary>
        /// Enums the lights
        /// </summary>
        public IEnumerable<LightRecord> EnumLights()
        {
            return this.Select(i => new LightRecord() { Index = this.IndexOf(i),  mData = this});
        }

        /// <summary>
        /// Sets the light visibility
        /// </summary>
        public void SetVisible(int index, bool visible)
        {
            this[index].IsEnabled = visible;
        }

        /// <summary>
        /// Renders the lights' configuration
        /// </summary>
        public void Render(IEngine engine)
        {
            for (int i = 0; i < this.Count; i++)
            {
                Light light = this[i];
                light.Render(engine);
            }
        }

        /// <summary>
        /// Renders the crosses representing the position of the lights
        /// </summary>
        public void RenderLightCrosses(IEngine engine)
        {
            for (int i = 0; i < this.Count; i++)
            {
                Light light = this[i];
                if (light.IsEnabled)
                {
                    light.RenderLightCross(engine);
                }
            }         
        }
    }
}
